use std::rc::Rc;

#[derive(PartialEq, Debug)]
struct SmartPoint {
    value: u32,
}

impl Drop for SmartPoint {
    fn drop(&mut self) {
        println!("The object will be dropped,value is {}", self.value);
    }
}

pub fn point_test() {
    let _sp_one = SmartPoint { value: 12 };
    println!("_sp_one's value is {}", _sp_one.value);
    {
        let _sp_two = SmartPoint { value: 14 };
        println!("_sp_two's value is {}", _sp_two.value);
    }
}

struct Owner {
    name: String,
}

struct Gadget {
    id: i32,
    owner: Rc<Owner>,
}

pub fn rc_point_test() {
    let gadget_owner = Rc::new(Owner { name: String::from("张三") });
    println!(" ");
    println!("owner point is {:p},name is {}", gadget_owner, gadget_owner.name);
    let gadget_one = Rc::new(Gadget { id: 1, owner: Rc::clone(&gadget_owner) });
    println!("gadget_one point is {:p},id is {},name is {}", gadget_one.owner, gadget_one.id, gadget_one.owner.name);
//    let gadget_two = Rc::new(Gadget { id: 2, owner: Rc::clone(&gadget_owner) });
//    let gadget_three = Rc::new(Gadget { id: 3, owner: Rc::clone(&gadget_owner) });
//    let gadget_four = Rc::new(Gadget { id: 4, owner: Rc::clone(&gadget_owner) });
    println!("gadget_owner reference num :{}",Rc::strong_count(&gadget_owner));
}
